######################################################################
# Libraries

load("@fbcode_macros//build_defs:auto_headers.bzl", "AutoHeaders")
load("@fbcode_macros//build_defs:cpp_library.bzl", "cpp_library")
load("@fbcode_macros//build_defs:roar.bzl", "roar_no_jit")

oncall("fbcode_entropy_wardens_folly")

cpp_library(
    name = "concurrent_bit_set",
    headers = ["ConcurrentBitSet.h"],
    exported_deps = [":portability"],
)

cpp_library(
    name = "atomic_hash_array",
    headers = [
        "AtomicHashArray.h",
        "AtomicHashArray-inl.h",
    ],
    exported_deps = [
        ":thread_cached_int",
        ":utility",
        "//folly/detail:atomic_hash_utils",
        "//folly/detail:iterators",
        "//folly/hash:hash",
        "//folly/lang:bits",
        "//folly/lang:exception",
    ],
)

cpp_library(
    name = "atomic_hash_map",
    headers = [
        "AtomicHashMap.h",
        "AtomicHashMap-inl.h",
    ],
    exported_deps = [
        ":atomic_hash_array",
        ":c_portability",
        ":likely",
        ":thread_cached_int",
        "//folly/container:foreach",
        "//folly/detail:atomic_hash_utils",
        "//folly/detail:iterators",
        "//folly/hash:hash",
    ],
)

cpp_library(
    name = "atomic_linked_list",
    headers = [
        "AtomicIntrusiveLinkedList.h",
        "AtomicLinkedList.h",
    ],
    exported_deps = [":memory"],
)

cpp_library(
    name = "atomic_unordered_map",
    headers = ["AtomicUnorderedMap.h"],
    exported_deps = [
        ":conv",
        ":likely",
        ":random",
        ":scope_guard",
        ":traits",
        "//folly/detail:atomic_unordered_map_utils",
        "//folly/lang:bits",
        "//folly/portability:sys_mman",
        "//folly/portability:unistd",
    ],
)

cpp_library(
    name = "base64",
    headers = ["base64.h"],
    exported_deps = [
        ":c_portability",
        ":portability",
        "//folly/detail/base64_detail:base64_api",
        "//folly/detail/base64_detail:base64_common",
        "//folly/lang:exception",
        "//folly/memory:uninitialized_memory_hacks",
    ],
)

cpp_library(
    name = "benchmark_util",
    headers = [
        "BenchmarkUtil.h",
    ],
    exported_deps = [
        ":portability",
        "//folly/lang:hint",
    ],
)

cpp_library(
    name = "benchmark",
    srcs = ["Benchmark.cpp"],
    headers = ["Benchmark.h"],
    compiler_flags = roar_no_jit(),
    deps = [
        ":file_util",
        ":map_util",
        ":string",
        "//folly/detail:perf_scoped",
        "//folly/json:dynamic",
    ],
    exported_deps = [
        ":benchmark_util",
        ":portability",
        ":preprocessor",
        ":range",
        ":scope_guard",
        ":traits",
        "//folly/functional:invoke",
        "//folly/lang:hint",
        "//folly/portability:gflags",
    ],
    external_deps = [
        ("boost", None, "boost_regex"),
    ],
    exported_external_deps = [
        "boost",
        "glog",
    ],
)

cpp_library(
    # @shim
    name = "bits",
    headers = ["Bits.h"],
    exported_deps = ["//folly/lang:bits"],
)

cpp_library(
    name = "c_portability",
    headers = ["CPortability.h"],
    exported_deps = [
        "//folly/portability:config",
    ],
)

cpp_library(
    name = "cancellation_token",
    srcs = ["CancellationToken.cpp"],
    headers = [
        "CancellationToken.h",
        "CancellationToken-inl.h",
    ],
    compiler_flags = roar_no_jit(),
    deps = [
        ":optional",
        "//folly:scope_guard",
        "//folly/lang:new",
        "//folly/portability:memory",
        "//folly/synchronization/detail:sleeper",
    ],
    exported_deps = [
        ":cpp_attributes",
        ":function",
    ],
    exported_external_deps = [
        "glog",
    ],
)

cpp_library(
    name = "chrono",
    headers = ["Chrono.h"],
    exported_deps = [
        ":portability",
        "//folly/lang:exception",
        "//folly/portability:time",
    ],
)

cpp_library(
    name = "clock_gettime_wrappers",
    srcs = ["ClockGettimeWrappers.cpp"],
    headers = ["ClockGettimeWrappers.h"],
    compiler_flags = roar_no_jit(),
    deps = [
        ":c_portability",
        ":likely",
    ],
    exported_deps = [
        "//folly/portability:time",
    ],
    external_deps = [
        ("glibc", None, "dl"),
    ],
    exported_external_deps = [
        ("glibc", None, "rt"),
    ],
)

cpp_library(
    name = "concurrent_lazy",
    headers = ["ConcurrentLazy.h"],
    exported_deps = [
        "//folly/functional:invoke",
        "//folly/synchronization:delayed_init",
    ],
)

cpp_library(
    name = "concurrent_skip_list",
    headers = [
        "ConcurrentSkipList.h",
        "ConcurrentSkipList-inl.h",
    ],
    exported_deps = [
        ":constexpr_math",
        ":likely",
        ":memory",
        ":thread_local",
        "//folly/detail:iterators",
        "//folly/synchronization:micro_spin_lock",
    ],
    exported_external_deps = [
        "glog",
        ("boost", None, "boost_random"),
    ],
)

cpp_library(
    name = "config",
    # @fb-only: headers = ["folly-config.h"], 
    headers = ["//:folly-config.h"], # @oss-only
    tags = ["oss_dependency"], # @oss-only
)

cpp_library(
    name = "constexpr_math",
    headers = ["ConstexprMath.h"],
    exported_deps = [
        ":portability",
        "//folly/lang:checked_math",
        "//folly/portability:constexpr",
    ],
)

cpp_library(
    name = "constructor_callback_list",
    headers = [
        "ConstructorCallbackList.h",
    ],
    exported_deps = [
        ":format",
        ":function",
        ":shared_mutex",
        "//folly/detail:static_singleton_manager",
    ],
)

cpp_library(
    name = "conv",
    srcs = ["Conv.cpp"],
    headers = ["Conv.h"],
    compiler_flags = roar_no_jit(),
    undefined_symbols = True,  # TODO(T23121628): fix deps and remove
    deps = [
        "fbsource//third-party/fast_float:fast_float",
        "//folly/lang:safe_assert",
    ],
    exported_deps = [
        ":c_portability",
        ":demangle",
        ":expected",
        ":fbstring",
        ":likely",
        ":portability",
        ":range",
        ":traits",
        ":unit",
        ":utility",
        "//folly/lang:exception",
        "//folly/lang:pretty",
        "//folly/lang:to_ascii",
        "//folly/portability:math",
    ],
    exported_external_deps = [
        "double_conversion",
    ],
)

cpp_library(
    name = "cpp_attributes",
    headers = ["CppAttributes.h"],
    exported_deps = [":portability"],
)

cpp_library(
    name = "cpu_id",
    headers = ["CpuId.h"],
    exported_deps = [":portability"],
)

cpp_library(
    name = "default_keep_alive_executor",
    headers = [
        "DefaultKeepAliveExecutor.h",
    ],
    exported_deps = [
        ":executor",
        "//folly/executors:sequenced_executor",
        "//folly/synchronization:baton",
    ],
    exported_external_deps = [
        "glog",
    ],
)

cpp_library(
    name = "demangle",
    srcs = ["Demangle.cpp"],
    headers = ["Demangle.h"],
    compiler_flags = roar_no_jit(),
    os_deps = [(
        "linux",
        ["third-party//binutils:iberty"],
    )],
    deps = [
        ":c_portability",
        ":cpp_attributes",
        ":utility",
        "//folly/functional:invoke",
        "//folly/lang:c_string",
    ],
    exported_deps = [
        ":fbstring",
        "//folly/portability:config",
    ],
)

cpp_library(
    name = "discriminated_ptr",
    headers = ["DiscriminatedPtr.h"],
    exported_deps = [
        ":likely",
        ":portability",
        "//folly/detail:discriminated_ptr_detail",
    ],
    exported_external_deps = [
        "glog",
    ],
)

cpp_library(
    name = "dynamic",
    headers = [
        "DynamicConverter.h",
        "dynamic.h",
        "dynamic-inl.h",
        "json.h",
    ],
    exported_deps = [
        "//folly/json:dynamic",
    ],
)

cpp_library(
    name = "exception",
    headers = ["Exception.h"],
    exported_deps = [
        ":conv",
        ":fbstring",
        ":likely",
        ":portability",
        "//folly/portability:sys_types",
    ],
)

cpp_library(
    name = "exception_string",
    srcs = ["ExceptionString.cpp"],
    headers = ["ExceptionString.h"],
    compiler_flags = roar_no_jit(),
    deps = [
        ":demangle",
        "//folly/lang:exception",
        "//folly/lang:type_info",
    ],
    exported_deps = [
        ":fbstring",
    ],
)

cpp_library(
    name = "exception_wrapper",
    srcs = ["ExceptionWrapper.cpp"],
    headers = [
        "ExceptionWrapper.h",
        "ExceptionWrapper-inl.h",
    ],
    compiler_flags = roar_no_jit(),
    undefined_symbols = True,  # TODO(T23121628): fix deps and remove
    deps = [
        ":glog",
    ],
    exported_deps = [
        ":c_portability",
        ":cpp_attributes",
        ":demangle",
        ":exception_string",
        ":fbstring",
        ":portability",
        ":traits",
        ":utility",
        "//folly/functional:traits",
        "//folly/lang:assume",
        "//folly/lang:exception",
    ],
)

cpp_library(
    name = "executor",
    srcs = ["Executor.cpp"],
    headers = [
        "Executor.h",
    ],
    compiler_flags = roar_no_jit(),
    deps = [
        ":exception_string",
        ":portability",
    ],
    exported_deps = [
        ":function",
        ":optional",
        ":range",
        ":utility",
        "//folly/lang:exception",
    ],
    external_deps = [
        "glog",
    ],
)

cpp_library(
    name = "expected",
    headers = ["Expected.h"],
    exported_deps = [
        ":c_portability",
        ":cpp_attributes",
        ":likely",
        ":portability",
        ":preprocessor",
        ":traits",
        ":unit",
        ":utility",
        "//folly/coro:coroutine",
        "//folly/lang:exception",
        "//folly/lang:hint",
    ],
)

cpp_library(
    name = "fbstring",
    headers = ["FBString.h"],
    exported_deps = [
        "fbsource//third-party/fmt:fmt",
        ":c_portability",
        ":cpp_attributes",
        ":likely",
        ":portability",
        ":traits",
        "//folly/hash:hash",
        "//folly/lang:assume",
        "//folly/lang:checked_math",
        "//folly/lang:exception",
        "//folly/memory:malloc",
    ],
)

cpp_library(
    name = "fbvector",
    headers = [
        "FBVector.h",
    ],
    exported_deps = [
        "//folly/container:fbvector",
    ],
)

cpp_library(
    name = "file",
    srcs = ["File.cpp"],
    headers = ["File.h"],
    compiler_flags = roar_no_jit(),
    deps = [
        ":exception",
        ":file_util",
        ":scope_guard",
        "//folly/portability:fmt_compile",
        "//folly/portability:sys_file",
    ],
    exported_deps = [
        ":exception_wrapper",
        ":expected",
        ":file_util",  # @manual
        ":portability",
        ":range",
        "//folly/portability:fcntl",
        "//folly/portability:unistd",
    ],
    external_deps = [
        "glog",
    ],
)

cpp_library(
    name = "file_util",
    srcs = ["FileUtil.cpp"],
    headers = ["FileUtil.h"],
    compiler_flags = roar_no_jit(),
    deps = [
        "//folly/detail:file_util_detail",
        "//folly/detail:file_util_vector_detail",
        "//folly/net:net_ops",
        "//folly/portability:sockets",
        "//folly/portability:stdlib",
        "//folly/portability:sys_file",
        "//folly/portability:sys_stat",
    ],
    exported_deps = [
        ":portability",
        ":range",
        ":scope_guard",
        "//folly/net:network_socket",
        "//folly/portability:fcntl",
        "//folly/portability:sys_uio",
        "//folly/portability:unistd",
    ],
)

cpp_library(
    name = "fingerprint",
    srcs = ["Fingerprint.cpp"],
    headers = ["Fingerprint.h"],
    compiler_flags = roar_no_jit(),
    deps = [
        ":portability",
        ":utility",
        "//folly/detail:fingerprint_polynomial",
    ],
    exported_deps = [
        ":range",
    ],
)

cpp_library(
    name = "fixed_string",
    headers = ["FixedString.h"],
    exported_deps = [
        ":constexpr_math",
        ":portability",
        ":range",
        ":utility",
        "//folly/lang:exception",
        "//folly/lang:ordering",
        "//folly/portability:constexpr",
    ],
)

cpp_library(
    name = "fmt_utility",
    srcs = [
        "FmtUtility.cpp",
    ],
    headers = [
        "FmtUtility.h",
    ],
    deps = [
        ":range",
        ":string",
        "//folly/ssl:openssl_hash",
    ],
    exported_deps = [
        "fbsource//third-party/fmt:fmt",
        ":cpp_attributes",
    ],
)

cpp_library(
    name = "format",
    srcs = [
        "Format.cpp",
    ],
    headers = [
        "Format.h",
        "Format-inl.h",
        "FormatArg.h",
    ],
    compiler_flags = roar_no_jit(),
    deps = [
        ":constexpr_math",
        ":cpp_attributes",
        "//folly/container:array",
    ],
    exported_deps = [
        ":c_portability",
        ":conv",
        ":exception",
        ":format_traits",
        ":likely",
        ":map_util",
        ":portability",
        ":range",
        ":string",
        ":traits",
        "//folly/lang:exception",
        "//folly/lang:to_ascii",
        "//folly/portability:windows",
    ],
    external_deps = [
        "double_conversion",
    ],
)

cpp_library(
    name = "format_traits",
    headers = ["FormatTraits.h"],
)

cpp_library(
    name = "function",
    headers = ["Function.h"],
    exported_deps = [
        ":cpp_attributes",
        ":portability",
        ":traits",
        "//folly/functional:invoke",
        "//folly/lang:align",
        "//folly/lang:exception",
        "//folly/lang:new",
    ],
)

cpp_library(
    name = "group_varint",
    srcs = [
        "GroupVarint.cpp",
    ],
    headers = ["GroupVarint.h"],
    compiler_flags = roar_no_jit(),
    deps = [
        "//folly/container:array",
    ],
    exported_deps = [
        ":portability",
        ":range",
        "//folly/detail:group_varint_detail",
        "//folly/lang:bits",
        "//folly/portability:builtins",
    ],
    exported_external_deps = [
        "glog",
    ],
)

cpp_library(
    name = "hash",
    headers = ["Hash.h"],
    exported_deps = [
        "//folly/hash:hash",
    ],
)

cpp_library(
    name = "indestructible",
    headers = ["Indestructible.h"],
    exported_deps = [
        ":traits",
        ":utility",
    ],
)

cpp_library(
    name = "indexed_mem_pool",
    headers = ["IndexedMemPool.h"],
    exported_deps = [
        ":portability",
        "//folly/concurrency:cache_locality",
        "//folly/portability:sys_mman",
        "//folly/portability:unistd",
        "//folly/synchronization:atomic_struct",
    ],
)

cpp_library(
    name = "intrusive_list",
    headers = [
        "IntrusiveList.h",
    ],
    exported_deps = [
        "//folly/container:intrusive_list",
    ],
)

cpp_library(
    name = "json",
    exported_deps = [
        ":dynamic",
    ],
)

cpp_library(
    name = "json_pointer",
    headers = [
        "json_pointer.h",
    ],
    exported_deps = [
        "//folly/json:json_pointer",
    ],
)

cpp_library(
    name = "json_patch",
    headers = [
        "json_patch.h",
    ],
    exported_deps = [
        "//folly/json:json_patch",
    ],
)

cpp_library(
    name = "lazy",
    headers = ["Lazy.h"],
    exported_deps = [
        ":optional",
        "//folly/functional:invoke",
    ],
)

cpp_library(
    name = "likely",
    headers = ["Likely.h"],
    exported_deps = [
        "//folly/lang:builtin",
    ],
)

cpp_library(
    name = "glog",
    headers = ["GLog.h"],
    exported_deps = [
        ":likely",
    ],
    exported_external_deps = [
        "glog",
    ],
)

cpp_library(
    name = "map_util",
    headers = [
        "MapUtil.h",
    ],
    exported_deps = [
        "//folly/container:map_util",
    ],
)

cpp_library(
    name = "math",
    headers = ["Math.h"],
)

cpp_library(
    name = "memset-impl",
    srcs = [
        "FollyMemset.cpp",
    ] + select({
        "DEFAULT": [],
        "ovr_config//cpu:x86_64": [
            "memset.S",
        ],
        "ovr_config//os:linux-arm64": [
            "memset_select_aarch64.cpp",
        ],
    }),
    auto_headers = AutoHeaders.NONE,
    headers = [],
    arch_preprocessor_flags = {
        "x86_64": [
            "-mavx2",
        ],
    },
    compiler_flags = roar_no_jit(),
    modular_headers = False,
    exported_deps = select({
        "DEFAULT": [],
        "ovr_config//os:linux-arm64": [
            "//folly/external/aor:memset_aarch64",  # @manual
        ],
    }),
)

# This exports the symbol __folly_memset to C++ via a header.
cpp_library(
    name = "memset",
    headers = ["FollyMemset.h"],
    exported_deps = [
        ":memset-impl",  # @manual
    ],
)

# This overrides the libc memset with __folly_memset.
cpp_library(
    name = "memset-use",
    srcs = [
        "FollyMemset.cpp",
    ] + select({
        "DEFAULT": [],
        "ovr_config//cpu:x86_64": [
            "memset.S",
        ],
        "ovr_config//os:linux-arm64": [
            "memset_select_aarch64.cpp",
        ],
    }),
    auto_headers = AutoHeaders.NONE,
    headers = [],
    arch_preprocessor_flags = {
        "aarch64": [
            "-DFOLLY_MEMSET_IS_MEMSET",
        ],
        "x86_64": [
            "-DFOLLY_MEMSET_IS_MEMSET",
            "-mavx2",
        ],
    },
    compiler_flags = roar_no_jit(),
    link_whole = True,  # Set link_whole to force linker to use __folly_memset
    modular_headers = False,
    exported_deps = select({
        "DEFAULT": [],
        "ovr_config//os:linux-arm64": [
            "//folly/external/aor:memset_aarch64-use",  # @manual
        ],
    }),
)

# This adds the symbol __folly_memcpy but does not replace the default memcpy.
cpp_library(
    name = "memcpy-impl",
    srcs = [
        "FollyMemcpy.cpp",
    ] + select({
        "ovr_config//cpu:x86_64": [
            "memcpy.S",
        ],
        "ovr_config//os:linux-arm64": [
            "memcpy_select_aarch64.cpp",
        ],
    }),
    auto_headers = AutoHeaders.NONE,
    headers = [],
    arch_preprocessor_flags = {
        "x86_64": [
            "-mavx2",
        ],
    },
    compiler_flags = roar_no_jit(),
    modular_headers = False,
    exported_deps = select({
        "DEFAULT": [],
        "ovr_config//os:linux-arm64": [
            "//folly/external/aor:memcpy_aarch64",  # @manual
        ],
    }),
)

# This exports the symbol __folly_memcpy to C++ via a header.
cpp_library(
    name = "memcpy",
    headers = ["FollyMemcpy.h"],
    exported_deps = [
        ":memcpy-impl",  # @manual
    ],
)

# This overrides the libc memcpy with __folly_memcpy.
cpp_library(
    name = "memcpy-use",
    srcs = [
        "FollyMemcpy.cpp",
    ] + select({
        "DEFAULT": [],
        "ovr_config//cpu:x86_64": [
            "memcpy.S",
        ],
        "ovr_config//os:linux-arm64": [
            "memcpy_select_aarch64.cpp",
        ],
    }),
    auto_headers = AutoHeaders.NONE,
    headers = [],
    arch_preprocessor_flags = {
        "aarch64": [
            "-DFOLLY_MEMCPY_IS_MEMCPY",
        ],
        "x86_64": [
            "-DFOLLY_MEMCPY_IS_MEMCPY",
            "-mavx2",
            "-march=haswell",
        ],
    },
    compiler_flags = roar_no_jit(),
    link_whole = True,  # Set link_whole to force linker to use __folly_memcpy
    modular_headers = False,
    exported_deps = select({
        "DEFAULT": [],
        "ovr_config//os:linux-arm64": [
            "//folly/external/aor:memcpy_aarch64-use",  # @manual
        ],
    }),
)

cpp_library(
    name = "memory",
    headers = ["Memory.h"],
    exported_deps = [
        ":constexpr_math",
        ":likely",
        ":portability",
        ":traits",
        ":utility",
        "//folly/functional:invoke",
        "//folly/lang:align",
        "//folly/lang:exception",
        "//folly/lang:thunk",
        "//folly/memory:malloc",
        "//folly/portability:config",
        "//folly/portability:constexpr",
        "//folly/portability:malloc",
    ],
)

cpp_library(
    name = "micro_lock",
    srcs = ["MicroLock.cpp"],
    headers = ["MicroLock.h"],
    compiler_flags = roar_no_jit(),
    deps = [
        "//folly/portability:asm",
    ],
    exported_deps = [
        ":optional",
        ":portability",
        "//folly/detail:futex",
    ],
)

cpp_library(
    # @shim
    name = "micro_spin_lock",
    headers = ["MicroSpinLock.h"],
    exported_deps = ["//folly/synchronization:micro_spin_lock"],
)

cpp_library(
    name = "move_wrapper",
    headers = ["MoveWrapper.h"],
)

cpp_library(
    name = "mpmc_pipeline",
    headers = ["MPMCPipeline.h"],
    exported_deps = [
        ":portability",
        "//folly/detail:mpmc_pipeline_detail",
    ],
    exported_external_deps = [
        "glog",
    ],
)

cpp_library(
    name = "mpmc_queue",
    headers = ["MPMCQueue.h"],
    exported_deps = [
        ":traits",
        "//folly/concurrency:cache_locality",
        "//folly/detail:turn_sequencer",
        "//folly/portability:unistd",
    ],
)

cpp_library(
    name = "network_address",
    srcs = [
        "IPAddress.cpp",
        "IPAddressV4.cpp",
        "IPAddressV6.cpp",
        "MacAddress.cpp",
        "SocketAddress.cpp",
    ],
    headers = [
        "IPAddress.h",
        "IPAddressException.h",
        "IPAddressV4.h",
        "IPAddressV6.h",
        "MacAddress.h",
        "SocketAddress.h",
    ],
    compiler_flags = roar_no_jit(),
    deps = [
        "fbsource//third-party/fmt:fmt",
        ":exception",
        ":format",
        ":scope_guard",
        ":small_vector",
        ":string",
        "//folly/detail:ip_address_source",
        "//folly/net:net_ops",
    ],
    exported_deps = [
        ":c_portability",
        ":constexpr_math",
        ":conv",
        ":expected",
        ":fbstring",
        ":optional",
        ":portability",
        ":range",
        ":unit",
        "//folly/detail:ip_address",
        "//folly/hash:hash",
        "//folly/lang:bits",
        "//folly/lang:exception",
        "//folly/net:network_socket",
        "//folly/portability:sockets",
    ],
    external_deps = [
        "boost",
    ],
)

cpp_library(
    name = "observer_container",
    headers = [
        "ObserverContainer.h",
    ],
    exported_deps = [
        ":constructor_callback_list",
        ":function",
        ":optional",
        ":scope_guard",
        ":small_vector",
        "//folly/io/async:destructor_check",
    ],
    exported_external_deps = [
        "glog",
    ],
)

cpp_library(
    name = "optional",
    headers = ["Optional.h"],
    exported_deps = [
        ":portability",
        ":traits",
        ":utility",
        "//folly/coro:coroutine",
        "//folly/hash:traits",
        "//folly/lang:exception",
    ],
)

cpp_library(
    name = "replaceable",
    headers = [
        "Replaceable.h",
    ],
    exported_deps = [
        ":portability",
        ":traits",
        ":utility",
    ],
)

cpp_library(
    name = "overload",
    headers = ["Overload.h"],
    exported_deps = [
        ":portability",
        ":traits",
        "//folly/functional:invoke",
    ],
)

cpp_library(
    name = "packed_sync_ptr",
    headers = ["PackedSyncPtr.h"],
    exported_deps = [
        ":portability",
        "//folly/synchronization:small_locks",
    ],
    exported_external_deps = [
        "glog",
    ],
)

cpp_library(
    name = "padded",
    headers = ["Padded.h"],
    exported_deps = [
        ":portability",
        ":traits",
        "//folly/functional:invoke",
        "//folly/portability:sys_types",
    ],
    exported_external_deps = [
        "boost",
    ],
)

cpp_library(
    name = "portability",
    headers = ["Portability.h"],
    exported_deps = [
        ":c_portability",
        "//folly/portability:config",
    ],
)

cpp_library(
    name = "preprocessor",
    headers = ["Preprocessor.h"],
    exported_deps = [
        ":c_portability",
    ],
)

cpp_library(
    name = "poly",
    headers = [
        "Poly.h",
        "Poly-inl.h",
    ],
    exported_deps = [
        ":c_portability",
        ":cpp_attributes",
        ":poly_exception",
        ":traits",
        "//folly/detail:poly_detail",
        "//folly/detail:typelist",
        "//folly/lang:assume",
    ],
)

cpp_library(
    name = "poly_exception",
    headers = ["PolyException.h"],
    exported_deps = [
        "//folly:c_portability",
    ],
)

cpp_library(
    name = "producer_consumer_queue",
    headers = ["ProducerConsumerQueue.h"],
    exported_deps = [
        "//folly/concurrency:cache_locality",
    ],
)

cpp_library(
    name = "random",
    srcs = [
        "Random.cpp",
    ],
    headers = [
        "Random.h",
        "Random-inl.h",
    ],
    compiler_flags = roar_no_jit(),
    os_deps = [(
        "windows",
        [
            "fbsource//third-party/toolchains/win:advapi32.lib",
        ],
    )],
    deps = [
        ":cpp_attributes",
        ":singleton_thread_local",
        ":thread_local",
        "//folly/detail:file_util_detail",
        "//folly/portability:config",
        "//folly/portability:sys_time",
        "//folly/portability:unistd",
        "//folly/synchronization:relaxed_atomic",
    ],
    exported_deps = [
        ":portability",
        ":traits",
        "//folly/functional:invoke",
        "//folly/lang:bits",
    ],
    external_deps = [
        "glog",
    ],
)

cpp_library(
    name = "range",
    headers = ["Range.h"],
    exported_deps = [
        "fbsource//third-party/fmt:fmt",
        ":cpu_id",
        ":likely",
        ":portability",
        ":traits",
        "//folly/detail:range_common",
        "//folly/detail:range_simd",
        "//folly/hash:spooky_hash_v2",
        "//folly/lang:c_string",
        "//folly/lang:exception",
        "//folly/portability:constexpr",
    ],
)

cpp_library(
    # @shim
    name = "rw_spin_lock",
    headers = ["RWSpinLock.h"],
    exported_deps = ["//folly/synchronization:rw_spin_lock"],
)

cpp_library(
    name = "scope_guard",
    srcs = ["ScopeGuard.cpp"],
    headers = ["ScopeGuard.h"],
    compiler_flags = roar_no_jit(),
    exported_deps = [
        ":portability",
        ":preprocessor",
        ":utility",
        "//folly/lang:exception",
        "//folly/lang:uncaught_exceptions",
    ],
)

cpp_library(
    name = "shared_mutex",
    srcs = ["SharedMutex.cpp"],
    headers = ["SharedMutex.h"],
    compiler_flags = roar_no_jit(),
    supports_python_dlopen = True,
    deps = [
        ":indestructible",
        "//folly/lang:exception",
        "//folly/portability:sys_resource",
    ],
    exported_deps = [
        ":c_portability",
        ":cpp_attributes",
        ":likely",
        "//folly/chrono:hardware",
        "//folly/concurrency:cache_locality",
        "//folly/detail:futex",
        "//folly/portability:asm",
        "//folly/synchronization:lock",
        "//folly/synchronization:relaxed_atomic",
        "//folly/synchronization:sanitize_thread",
        "//folly/system:thread_id",
    ],
)

cpp_library(
    name = "singleton",
    srcs = [
        "Singleton.cpp",
    ],
    headers = [
        "Singleton.h",
        "Singleton-inl.h",
    ],
    compiler_flags = roar_no_jit(),
    deps = [
        "fbsource//third-party/fmt:fmt",
        ":demangle",
        ":scope_guard",
        "//folly/experimental/symbolizer:symbolizer",
        "//folly/lang:safe_assert",
        "//folly/portability:config",
        "//folly/portability:fmt_compile",
    ],
    exported_deps = [
        ":cancellation_token",
        ":exception",
        ":executor",
        ":memory",
        ":synchronized",
        "//folly/concurrency:core_cached_shared_ptr",
        "//folly/concurrency/memory:read_mostly_shared_ptr",
        "//folly/detail:singleton",
        "//folly/detail:static_singleton_manager",
        "//folly/hash:hash",
        "//folly/lang:exception",
        "//folly/memory:sanitize_leak",
        "//folly/synchronization:baton",
    ],
    external_deps = [
        ("glibc", None, "dl"),
        ("glibc", None, "rt"),
    ],
    exported_external_deps = [
        "glog",
    ],
)

cpp_library(
    name = "singleton_thread_local",
    srcs = ["SingletonThreadLocal.cpp"],
    headers = ["SingletonThreadLocal.h"],
    compiler_flags = roar_no_jit(),
    exported_deps = [
        ":scope_guard",
        ":thread_local",
        "//folly/detail:iterators",
        "//folly/detail:singleton",
        "//folly/detail:unique_instance",
        "//folly/functional:invoke",
        "//folly/lang:hint",
    ],
)

cpp_library(
    name = "small_vector",
    headers = [
        "small_vector.h",
    ],
    exported_deps = [
        "//folly/container:small_vector",
    ],
)

cpp_library(
    name = "sorted_vector_types",
    headers = [
        "sorted_vector_types.h",
    ],
    exported_deps = [
        "//folly/container:sorted_vector_types",
    ],
)

cpp_library(
    name = "spin_lock",
    headers = [
        "SpinLock.h",
    ],
    exported_deps = [
        ":portability",
        "//folly/synchronization:small_locks",
    ],
)

cpp_library(
    name = "stop_watch",
    headers = ["stop_watch.h"],
    exported_deps = [
        ":chrono",
        ":utility",
        "//folly/portability:time",
    ],
)

cpp_library(
    name = "string",
    srcs = [
        "String.cpp",
    ],
    headers = [
        "String.h",
        "String-inl.h",
    ],
    compiler_flags = roar_no_jit(),
    deps = [
        "//folly/container:array",
    ],
    exported_deps = [
        ":conv",
        ":cpp_attributes",
        ":exception_string",
        ":optional",
        ":portability",
        ":range",
        ":scope_guard",
        ":traits",
        ":unit",
        "//folly/container:reserve",
        "//folly/detail:simple_simd_string_utils",
        "//folly/detail:split_string_simd",
    ],
    external_deps = [
        "glog",
    ],
)

cpp_library(
    name = "subprocess",
    srcs = ["Subprocess.cpp"],
    headers = ["Subprocess.h"],
    compiler_flags = roar_no_jit(),
    deps = [
        ":conv",
        ":scope_guard",
        ":string",
        "//folly/lang:assume",
        "//folly/logging:logging",
        "//folly/portability:dirent",
        "//folly/portability:fcntl",
        "//folly/portability:sockets",
        "//folly/portability:stdlib",
        "//folly/portability:sys_syscall",
        "//folly/portability:unistd",
        "//folly/system:at_fork",
        "//folly/system:shell",
    ],
    exported_deps = [
        ":exception",
        ":file",
        ":file_util",
        ":function",
        ":map_util",
        ":optional",
        ":portability",
        ":range",
        "//folly/gen:string",
        "//folly/io:iobuf",
        "//folly/portability:sys_resource",
    ],
    external_deps = [
        ("boost", None, "boost_range"),
    ],
    exported_external_deps = [
        "boost",
        ("boost", None, "boost_container"),
    ],
)

cpp_library(
    name = "synchronized",
    headers = ["Synchronized.h"],
    exported_deps = [
        ":function",
        ":likely",
        ":preprocessor",
        ":shared_mutex",
        ":traits",
        ":utility",
        "//folly/container:foreach",
        "//folly/functional:apply_tuple",
        "//folly/synchronization:lock",
    ],
    exported_external_deps = [
        "glog",
    ],
)

cpp_library(
    name = "synchronized_ptr",
    headers = ["SynchronizedPtr.h"],
    exported_deps = [":synchronized"],
)

cpp_library(
    name = "thread_cached_int",
    headers = ["ThreadCachedInt.h"],
    exported_deps = [
        ":likely",
        ":thread_local",
    ],
)

cpp_library(
    name = "thread_local",
    headers = ["ThreadLocal.h"],
    exported_deps = [
        ":likely",
        ":portability",
        ":scope_guard",
        ":shared_mutex",
        "//folly/detail:thread_local_detail",
    ],
)

cpp_library(
    name = "timeout_queue",
    srcs = ["TimeoutQueue.cpp"],
    headers = ["TimeoutQueue.h"],
    compiler_flags = roar_no_jit(),
    exported_external_deps = [
        "boost",
        ("boost", None, "boost_multi_index"),
    ],
)

cpp_library(
    name = "token_bucket",
    headers = ["TokenBucket.h"],
    exported_deps = [
        ":constexpr_math",
        ":likely",
        ":optional",
        "//folly/concurrency:cache_locality",
    ],
)

cpp_library(
    name = "traits",
    headers = ["Traits.h"],
    exported_deps = [":portability"],
)

cpp_library(
    name = "try",
    srcs = [
        "Try.cpp",
    ],
    headers = [
        "Try.h",
        "Try-inl.h",
    ],
    compiler_flags = roar_no_jit(),
    exported_deps = [
        ":exception_wrapper",
        ":likely",
        ":memory",
        ":portability",
        ":unit",
        ":utility",
        "//folly/functional:invoke",
        "//folly/lang:exception",
    ],
)

cpp_library(
    name = "unicode",
    srcs = ["Unicode.cpp"],
    headers = ["Unicode.h"],
    compiler_flags = roar_no_jit(),
    deps = [
        ":conv",
    ],
    exported_deps = [
        "//folly/lang:exception",
    ],
)

cpp_library(
    name = "unit",
    headers = ["Unit.h"],
)

cpp_library(
    name = "uri",
    srcs = [
        "Uri.cpp",
    ],
    headers = [
        "Uri.h",
        "Uri-inl.h",
    ],
    compiler_flags = roar_no_jit(),
    exported_deps = [
        ":conv",
        ":expected",
        ":string",
        "//folly/hash:hash",
    ],
    external_deps = [
        ("boost", None, "boost_regex"),
    ],
)

cpp_library(
    name = "utf8_string",
    headers = [
        "UTF8String.h",
    ],
    exported_deps = [
        ":range",
    ],
    exported_external_deps = [
        ("boost", None, "boost_regex"),
    ],
)

# For things that would go in c++ stdlib <utility>:
cpp_library(
    name = "utility",
    headers = [
        "Utility.h",
    ],
    exported_deps = [
        ":c_portability",
        ":portability",
        ":traits",
    ],
)

cpp_library(
    name = "varint",
    headers = ["Varint.h"],
    exported_deps = [
        ":conv",
        ":expected",
        ":likely",
        ":portability",
        ":range",
    ],
)

cpp_library(
    name = "virtual_executor",
    headers = [
        "VirtualExecutor.h",
    ],
    exported_deps = [
        "//folly/executors:virtual_executor",
    ],
)

cpp_library(
    name = "maybe_managed_ptr",
    headers = ["MaybeManagedPtr.h"],
    deps = [
    ],
    exported_deps = [
    ],
)
